package cn.com.cpic.insurance.rulecheck.core.condition;

import cn.com.cpic.insurance.rulecheck.core.Context;
import cn.com.cpic.insurance.rulecheck.core.exception.OperateException;
import cn.com.cpic.insurance.rulecheck.core.expression.Expression;
import cn.com.cpic.insurance.rulecheck.core.javacc.RuleCheck;

/**
 * 通过表达式来表述操作的条件
 * 
 * @author 代波
 * @since 2011-8-14
 */
public final class ExpressionCondition extends AbstractCondition {
	private static final long serialVersionUID = 4443961056167409337L;

	private final Expression<Boolean> expression;

	public ExpressionCondition(String token, String expression) {
		super(token);
		this.expression = RuleCheck.parseLogicalExpression(expression);
	}

	public Boolean operate(Context context) throws OperateException {
		return expression.operate(context);
	}
}
